package com.yoomiito.app.ui.video.clip

import androidx.recyclerview.widget.RecyclerView
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import cn.jzvd.Jzvd
import cn.jzvd.JzvdStd
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.yoomiito.app.R
import com.yoomiito.app.base.BaseActivity
import com.yoomiito.app.model.home.VideoClipInfo
import com.yoomiito.app.ui.anyview.videoclip.RollingMsgView
import com.yoomiito.app.ui.anyview.videoclip.VideoClipBottomView
import com.yoomiito.app.utils.ImageLoader
import com.yoomiito.app.utils.L
import com.yoomiito.app.widget.videoplayer.VideoPlayer

class VideoClipAdapter(datas: List<VideoClipInfo>?,var autoPlay:Boolean = true) : BaseQuickAdapter<VideoClipInfo, BaseViewHolder>(R.layout.item_video_clip, datas) {

    override fun convert(helper: BaseViewHolder?, item: VideoClipInfo?) {
        val video = helper?.getView<VideoPlayer>(R.id.videoPlayer)
        video?.isAutoPlay = true
        video?.setUp(item?.video_url, "",JzvdStd.SCREEN_NORMAL)//, JZMediaIjk::class.java
//        video?.bottomContainer?.visibility = View.GONE
//        video?.bottomProgressBar?.visibility = View.GONE
        video?.progressBar?.visibility = View.GONE
        video?.fullscreenButton?.visibility = View.GONE
        video?.totalTimeTextView?.visibility = View.GONE
        Jzvd.SAVE_PROGRESS = false
        ImageLoader.getInstance().into(mContext,item?.video_img,video?.thumbImageView)
        if (autoPlay) video?.startButton?.performClick()
        val bottomViewParent = helper?.getView<FrameLayout>(R.id.bottomViewParent)
        if(bottomViewParent?.childCount==0){
            bottomViewParent?.addView(VideoClipBottomView(mContext as BaseActivity<*>,item),
                    FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT))
        }else{
            val vcb = bottomViewParent?.getChildAt(0) as VideoClipBottomView
            vcb.updateInfo(item)
        }
    }

}